<?php

namespace common\helpers;

use yii\helpers\BaseArrayHelper;
use yii\queue\JobInterface;

/**
 * 队列扩展类
 *
 * @author emhome<emhome@163.com>
 * @since 2.0
 */
class QueueHelper {

    /**
     * 执行队列
     * @param \yii\queue\JobInterface $job
     * @param type $delay
     */
    public function re() {
        
    }

    /**
     * 执行队列
     * @param \yii\queue\JobInterface $job
     * @param type $delay
     */
    public static function doque(JobInterface $job, $delay = 0) {

        Yii::$app->queue->on(Queue::EVENT_AFTER_ERROR, function ($event) {
            if ($event->error instanceof TemporaryUnprocessableJobException) {
                $queue = $event->sender;
                $queue->delay(7200)->push($event->job);
            }
        });

        // 将作业推送到队列并获得其ID
        $id = Yii::$app->queue->delay(1 * 30)->push(new Job([
            'url' => 'http://img.netpc.com.cn/2018/06/12080502tmd.jpg',
            'file' => 'c:\2.jpg',
        ]));
    }

}
